﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Giaiphongmatbang.DataModel;

namespace Giaiphongmatbang.UserControl
{
    public partial class Login : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetValue();
            }
        }

        protected void SetValue()
        {
            User user = (User)Session["User"];
            if (user == null)
            {
                lbtLogin.Text = "Đăng nhập";
                lbtUser.Visible = false;
            }
            else
            {
                lbtUser.Text = " Xin chào: " + user.DisplayName;
                lbtLogin.Text = "Thoát";
            }           
        }
        protected void lbtLogin_Click(object sender, EventArgs e)
        {
            if (Session["User"] == null)
            {
                Session["returnURL"] = Request.RawUrl == "Login.aspx" ? "duan.aspx" : Request.RawUrl;
                Response.Redirect("Login.aspx");
            }
            else
            {
                Session.Clear();
                Response.Redirect("duan.aspx");
            }
        }

        protected void lbtUser_Click(object sender, EventArgs e)
        {
            Response.Redirect("quanlythongtincanhan.aspx?ID=" + ((User)Session["User"]).UserID);
        }
    }
}